home *** CD-ROM | disk | FTP | other *** search
- { TMPasArea.pas written by Stephen Dubin, V.M.D., Ph.D.}
- { Prepared for use with TML Pascal System 2.0}
- { Latest Revision 8/29/87}
- program TMPasArea;
-
- {$T APPL AREA } { set the type and creator}
- {$B+ } { set the bundle bit}
- {$L TMPasAreaRes } { link the resource file too...}
-
- uses MacIntf;
-
- const
- FileMenuID = 1; { the File menu}
- OptionMenuID = 2; { the option menu}
- WindResID = 1; { the resource id of my window}
-
- type
- BUF = array[1..512] of Integer; { Make it bigger if you are really paranoid}
-
- var
- myMenus : Array[FileMenuId..OptionMenuID] of MenuHandle;
- Done : Boolean;
- MyWindow : WindowPtr;
- TotalRegion : RgnHandle;
- Numpix : Longint;
- NumTrap : Longint;
- myBUF : BUF;
-
- { Declare the Assembly Language routine as external }
- function ACountPix( theRegion:RgnHandle) : LongInt; external;
- {$U ACountPix }
- {Note: It seems the .link file does not recognise this directive }
- {if it appears above with the other compiler directives}
-
- function CountPix(theRegion : RgnHandle): LongInt;
- var
- pt : Point;
- rgn : Region;
- temp : LongInt;
- x : Integer;
- y : Integer;
-
- begin
- temp := 0;
- rgn := theRegion^^;
- for x := rgn.rgnBBox.left to rgn.rgnBBox.right do
- begin
- pt.h := x;
- for y := rgn.rgnBBox.top to rgn.rgnBBox.bottom do
- begin
- pt.v := y;
- if PtInRgn( pt, TheRegion) then temp := temp + 1;
- end;
- end;
- CountPix := temp;
- end;
- { Notice: TML does not seem to like having pt.h and pt.v as control elements}
-
- procedure Wipe;
- var
- r : Rect;
-
-
- begin
- SetRect(r,0,0,504,300);
- EraseRect(r);
-
- end;
-
- procedure Data;
- var
- rgn : Region;
- rgnpntr : Ptr;
- size : Integer;
- thebuf : BUF;
- bfpntr : Ptr;
- myString : Str255;
- i : Integer;
- x : Integer;
- y : Integer;
-
- begin
- Wipe;
- TextSize(9);
- TextFont(Monaco);
- rgn := totalRegion^^;
- rgnpntr := ptr(totalRegion^);
- size := rgn.rgnSize;
- if size > 800 then size:= 800;
- bfpntr := ptr(@thebuf);
- BlockMove(rgnpntr,bfpntr,size);
- MoveTo(10,10);
- DrawString('Here are the first 400 words of the region data. (FLAG = 32767)');
- x := 10;
- y := 20;
- for i := 1 to (size div 2) do
- begin
- MoveTo(x,y);
- NumToString(theBuf[i],myString);
- if theBuf[i] < 32766 then
- begin
- if theBuf[i] <10 then DrawString(' ');
- if theBuf[i] <100 then DrawString(' ');
- if theBuf[i] < 1000 then DrawString(' ');
- if theBuf[i] < 10000 then DrawString(' ');
- DrawString(MyString);
- end;
- if theBuf[i] > 32766 then DrawString(' FLAG');
- x := x + 30;
- if (i mod 16) = 0 then
- begin
- x := 10;
- y := y+10;
- end;
- end;
-
- end;
-
-
- procedure OvalRegion;
- var
- RectA : Rect;
-
- begin
- Wipe;
- TotalRegion := NewRgn;
- SetRect(RectA, 170,175,195,200);
- OpenRgn;
- ShowPen;
- FrameOval(RectA);
- HidePen;
- CloseRgn(TotalRegion);
- end;
-
- procedure Contour;
- var
- p1 : Point;
- p2 : Point;
- OldTick : Longint;
-
- begin
-
- Wipe;
- TotalRegion := NewRgn;
- OldTick := TickCount;
- Repeat
- GetMouse(p1);
- MoveTo(p1.h,p1.v);
- p2 := p1;
- Until Button = True;
- OpenRgn;
- ShowPen;
- PenMode(patXor);
- Repeat
- GetMouse(p2);
- Repeat Until (OldTick <> TickCount);
- LineTo(p2.h,p2.v);
- Until Button <> True;
- Repeat Until (OldTick <> TickCount);
- LineTo(p1.h,p1.v);
- PenNormal;
- HidePen;
- CloseRgn(TotalRegion);
- InvertRgn(TotalRegion);
- end;
-
- procedure Example;
-
- begin
- Wipe;
- OpenRgn;
- TotalRegion := NewRgn;
- ShowPen;
- MoveTo(100,100);
- LineTo(200,100);
- LineTo(200,220);
- LineTo(180,220);
- LineTo(180,150);
- LineTo(125,150);
- LineTo(125,170);
- LineTo(125,170);
- LineTo(100,170);
- LineTo(100,100);
- HidePen;
- CloseRgn(TotalRegion);
- end;
-
- procedure FreeBox;
- var
- p1 : Point;
- p2 : Point;
- p3 : Point;
- OldTick : Longint;
- MyRect : Rect;
-
- begin
- Wipe;
- TotalRegion := NewRgn;
- OldTick := TickCount;
- PenPat(gray);
- PenMode(patXor);
- Repeat
- GetMouse(p1);
- p2 := p1;
- Until Button = True;
- OpenRgn;
- ShowPen;
- PenMode(patXor);
- Repeat
- Pt2Rect(p1,p2,MyRect);
- Repeat Until (OldTick <> TickCount);
- FrameRect(MyRect);
- Repeat
- GetMouse(p3);
- Until EqualPt(p2,p3) <> True;
- Repeat Until (OldTick <> TickCount);
- FrameRect(MyRect);
- p2 := p3;
- Until Button <> True;
- Pennormal;
- HidePen;
- PenPat(black);
- FrameRect(MyRect);
- CloseRgn(TotalRegion);
- InvertRgn(TotalRegion);
- end;
-
- procedure Area;
- var
- NumTix : LongInt;
- MoreTix : LongInt;
- TicString : Str255;
- PixString : Str255;
- TrapString : Str255;
-
- begin
- TextFont(Monaco);
- TextSize(9);
- TextMode(0);
- MoveTo(10,20); DrawString(' Using Pascal ');
- NumTix := TickCount;
- NumPix := CountPix( TotalRegion );
- MoreTix := TickCount - NumTix;
- NumToString(MoreTix,TicString);
- NumToString(NumPix,PixString);
- MoveTo(10,30); DrawString(' Tickcount = ');
- MoveTo(120,30); DrawString(TicString);
- MoveTo(10,40); DrawString(' Pixel Number = ');
- MoveTo(120,40); DrawString(PixString);
- MoveTo(10,50); DrawString(' Using Tom Terrific ');
- NumTix := TickCount;
- NumPix := ACountPix( TotalRegion );
- MoreTix := TickCount - NumTix;
- NumToString(MoreTix,TicString);
- NumToString(NumPix,PixString);
- MoveTo(10,60); DrawString(' Tickcount = ');
- MoveTo(120,60); DrawString(TicString);
- MoveTo(10,70); DrawString(' Pixel Number = ');
- MoveTo(120,70); DrawString(PixString);
- end;
-
- procedure ProcessMenu(codeWord : Longint);
- var
- menuNum : Integer;
- itemNum : Integer;
-
- begin
- if codeWord <> 0 then
- begin
- menuNum := HiWord(codeWord);
- itemNum := LoWord(codeWord);
- case menuNum of { the different menus}
- FileMenuID :Done := true;
- OptionMenuID :
- begin
- case ItemNum of
- 1:Contour; {Contour}
- 2:FreeBox; {Freebox}
- 3:OvalRegion; {Oval}
- 4:Example; {Example}
- 5: Area; {Area}
- 6:Data; {Region Data}
- end; { of ItemNum case}
- end;{ of MenuNum case}
- end;
- HiliteMenu(0);
- end;
- end;
-
- procedure DealWithMouseDowns(theEvent: EventRecord);
- var
- location : Integer;
- windowPointedTo : WindowPtr;
- mouseLoc : point;
- windowLoc : integer;
- VandH : Longint;
- Height : Integer;
- Width : Integer;
- begin
- mouseLoc := theEvent.where;
- windowLoc := FindWindow(mouseLoc,windowPointedTo);
- case windowLoc of
- inMenuBar :
- begin
- ProcessMenu(MenuSelect(mouseLoc));
- end;
-
- end;
- end;
-
- procedure MainEventLoop;
- var
- Event : EventRecord;
- theItem : integer;
-
- begin
- repeat
- SystemTask;
- if GetNextEvent(everyEvent, Event) then
- begin
- case Event.what of
- mouseDown : DealWithMouseDowns(Event);
- end;
- end;
- until Done;
- end;
-
- procedure MakeMenus;
- var
- index : Integer;
- begin
- for index := FileMenuId to OptionMenuID do
- begin
- myMenus[index] := GetMenu(index);
- InsertMenu(myMenus[index],0);
- end;
- DrawMenuBar;
- end;
-
-
- begin
- Done := false;
- FlushEvents(everyEvent,0);
- InitGraf(@thePort);
- InitFonts;
- InitWindows;
- InitMenus;
- InitDialogs(nil);
- InitCursor;
- MoreMasters;
- MoreMasters;
- MakeMenus;
- MyWindow := GetNewWindow(WindResID,nil,Pointer(-1));
- SetPort(MyWindow);
- TotalRegion := NewRgn; {Lazy way to avoid bomb if your select "Area" first}
- MainEventLoop;
- end.
-